/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ParameterMiniPanel.java
 *
 * Created on Dec 4, 2009, 9:08:43 PM
 */
package wekinator;

import java.text.DecimalFormat;
import javax.swing.JFrame;

/**
 *
 * @author rebecca
 */
public class ParameterMiniViewer extends javax.swing.JPanel {
    /** Creates new form ParameterMiniPanel */

    DecimalFormat dd = new DecimalFormat("#.##");
    public ParameterMiniViewer() {
        initComponents();
    }

    public ParameterMiniViewer(String name, double[] value) {
        initComponents();
        setValue(value);
        labelParamName.setText(name + ":");
    }

     public ParameterMiniViewer(String name, double value) {
        initComponents();
        setValue(value);
        labelParamName.setText(name + ":");
    }

        public void setValue(String s) {
            labelVal.setText(s);
        }

    public void setValue(double[] value) {
        if (value.length == 1) {
            labelVal.setText(dd.format(value[0]));
        } else {
            String s= "";
            for (int i = 0; i < value.length; i++) {
                s += dd.format(value[i]);
                if (i != value.length-1) {
                    s += "|";
                }
            }
            labelVal.setText(s);
        }

    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelVal = new javax.swing.JLabel();
        labelParamName = new javax.swing.JLabel();

        labelVal.setText(".01|.01|.05");

        labelParamName.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelParamName.setText("Parameter 3");
        labelParamName.setVerticalTextPosition(javax.swing.SwingConstants.TOP);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(labelParamName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 157, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(labelVal, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(labelParamName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)
                .add(labelVal))
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel labelParamName;
    private javax.swing.JLabel labelVal;
    // End of variables declaration//GEN-END:variables


    public void setValue(double value) {
       labelVal.setText(dd.format(value));
    }

    public static void main(String[] args) {
        JFrame f = new JFrame();
        double vals[] = new double[2];
        vals[0]= .5932985;
        vals[1] = .935729;
        ParameterMiniViewer p = new ParameterMiniViewer("Param1", vals);
        f.add(p);
        f.setVisible(true);
        p.setValue(3);
    }


}
